package ai.people.core.common.properties.elastic;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 社交媒体账号ES索引映射关系
 *
 * @author liguannan
 * @date 2022/6/9 13:28
 */
@Component
@ConfigurationProperties(prefix = "elastic.social.account")
public class ElasticSocialAccountIndex {

    private Map<String, String> cluster1IndexMap;
    private Map<String, String> cluster2IndexMap;

    public String getIndexBySource(String source, Integer cluster){
        if(cluster == 1){
            return cluster1IndexMap.get(source);
        }else if(cluster == 2){
            return cluster2IndexMap.get(source);
        }
        return null;
    }

    public String[] getIndexListBySources(List<String> sources, Integer cluster){
        if(cluster == 1){
            return sources.stream().map(cluster1IndexMap::get).collect(Collectors.toList()).toArray(new String[]{});
        }else if(cluster == 2){
            return sources.stream().map(cluster2IndexMap::get).collect(Collectors.toList()).toArray(new String[]{});
        }
        return null;
    }

    public Map<String, String> getCluster1IndexMap() {
        return cluster1IndexMap;
    }

    public void setCluster1IndexMap(Map<String, String> cluster1IndexMap) {
        this.cluster1IndexMap = cluster1IndexMap;
    }

    public Map<String, String> getCluster2IndexMap() {
        return cluster2IndexMap;
    }

    public void setCluster2IndexMap(Map<String, String> cluster2IndexMap) {
        this.cluster2IndexMap = cluster2IndexMap;
    }
}
